<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            height: 100px;
            width: 100px;
            background-color: pink;
        }

        .box {
            height: 200px;
            width: 200px;
            background-color: skyblue;
            border: 1px solid #000;
        }

        .nav {
            color: red;
        }
    </style>
</head>

<body>
    <div>123</div>
    <script>
        // 获取元素
        const div = document.querySelector('div');
        // 添加类名
        div.className = 'box nav';
    </script>
</body>

</html>